package de.axa.smartfix.monitoring.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

public class MonitorManager extends Observable {

	public static MonitorManager createMonitorManager() {
		return new MonitorManager();
	}

	List<IMonitor> rootList;

	private MonitorManager() {
		this.rootList = new ArrayList<IMonitor>();
	}

	public void updateModel() {
		for (IMonitor m : this.rootList) {
			m.update();
		}
	}

	private boolean add(IMonitor e) {
		e.setParent(this);
		return this.rootList.add(e);
	}

	private boolean remove(IMonitor o) {
		boolean success = this.rootList.remove(o);
		if (success) {
			o.setParent(null);
		}
		return success;
	}

	public IMonitor[] toArray() {
		return this.rootList.toArray(new IMonitor[0]);
	}
	
	public void addMonitor(IMonitor m) {
		add(m);
	}

}
